//# sourceURL=http://uMapApp/Module/RoadLine/RoadSideStakeNumModule
define([
    "mhjs/mhjs"
    , "uMap/uMap"
    , "uEarth/uEarth"
    , "../Module"
    , "../../UI/Panel/FloatPanel"
    , "../../UI/Panel/PanelBlock/ListBlock"
    , "../../UI/Panel/PanelBlock/PropertiesBlock"
    , "../../UI/Panel/Item/ListItem"
    , "../../UI/Layer"
    , "./RoadLine"
    , "../StakeNum/StakeNum"
    , "../StakeNum/Mileage"
    , "../../UI/QueryNode"
], function (
    mhjs,
    uMap,
    uEarth,
    Module,
    FloatPanel,
    ListBlock,
    PropertiesBlock,
    ListItem,
    Layer,
    RoadLine,
    StakeNum,
    Mileage
    , QueryNode
) {

    function RoadSideStakeNumModule(option) {

        var _this = this;
        Module.call(_this, option);

        _this.title = "路边桩号";
        _this.icon = _this.app.icons.stakeNum;
        _this.panels = [];
        _this.items = [];
        _this.layer = new Layer({
            "app": _this.app
        });

        _this.layer.pointPrimitives = new uMap.PointPrimitiveCollection();
        _this.layer.primitives.add(_this.layer.pointPrimitives.object);
        _this.layer.labelPrimitives = new uMap.LabelCollection();
        _this.layer.primitives.add(_this.layer.labelPrimitives.object);


    }

    var _class = RoadSideStakeNumModule;

    mhjs.Inherit(_class, Module);

    Object.defineProperties(_class.prototype, {
        "renderList": {
            value: function (list) {

                var _this = this;

                var KPOption = {
                    point: {
                        pixelSize                 : 5
                        , color                   : ["#ff0"]
                        , outlineColor            : ["#000"]
                        , outlineWidth            : 2
                        , level                   : [0, 1e5]
                        , disableDepthTestDistance: Number.POSITIVE_INFINITY
                    },
                    label: {
                        fillColor                 : ["#ff0"]
                        , outlineColor            : ["#000"]
                        , outlineWidth            : 5.0
                        , horizontalOrigin        : "CENTER"
                        , verticalOrigin          : "BOTTOM"
                        , pixelOffset             : [0, -10]
                        , level                   : [0, 5e4]
                        , disableDepthTestDistance: Number.POSITIVE_INFINITY
                    }
                };

                var HPOption = {
                    point: {
                        pixelSize                 : 3
                        , color                   : ["#fff"]
                        , outlineColor            : ["#000"]
                        , outlineWidth            : 1
                        , level                   : [0, 1e4]
                        , disableDepthTestDistance: Number.POSITIVE_INFINITY
                    },
                    label: {
                        font                      : "14px Microsoft Yahei"
                        , fillColor               : ["#fff"]
                        , outlineColor            : ["#000"]
                        , outlineWidth            : 5.0
                        , horizontalOrigin        : "CENTER"
                        , verticalOrigin          : "BOTTOM"
                        , pixelOffset             : [0, -7.5]
                        , level                   : [0, 5e3]
                        , disableDepthTestDistance: Number.POSITIVE_INFINITY
                    }
                };

                $.each(list, function (i, point) {

                    var stakeNum = new Mileage(point.stakeNum);

                    if (stakeNum.extend === 0) {

                        // var KP = new uMap.Entity({
                        //     objectOption: {
                        //         position: new uMap.Position(positionHeading.position),
                        //         point   : new uMap.PointGraphic({
                        //             objectOption: {
                        //                 color: ["#ff0"],
                        //                 level: [0, 1e5]
                        //             }
                        //         }),
                        //         label   : new uMap.LabelGraphic({
                        //             objectOption: {
                        //                 text                      : stakeNum.str
                        //                 , fillColor               : ["#ff0"]
                        //                 , verticalOrigin          : "BOTTOM"
                        //                 , pixelOffset             : [0, -10]
                        //                 , level                   : [0, 5e4]
                        //                 , disableDepthTestDistance: Number.POSITIVE_INFINITY
                        //             }
                        //         })
                        //     }
                        // });
                        // _this.items.push(_this.layer.dataSources.entities.add(KP.object));

                        _this.layer.pointPrimitives.add(
                            new uMap.PointOption(
                                $.extend(
                                    {},
                                    KPOption.point,
                                    {
                                        position: point.position
                                    })
                            )
                        );

                        _this.layer.labelPrimitives.add(
                            new uMap.LabelOption(
                                $.extend(
                                    {},
                                    KPOption.label,
                                    {
                                        position: point.position
                                        , text  : String(stakeNum.str)
                                    }
                                )
                            )
                        );


                    } else {

                        // var HP = new uMap.Entity({
                        //     objectOption: {
                        //         position: new uMap.Position(positionHeading.position),
                        //         point   : new uMap.PointGraphic({
                        //             objectOption: {
                        //                 pixelSize     : 3
                        //                 , outlineWidth: 1
                        //                 , color       : ["#fff"]
                        //                 , level       : [0, 1e4]
                        //             }
                        //         }),
                        //         label   : new uMap.LabelGraphic({
                        //             objectOption: {
                        //                 font                      : "14px Microsoft Yahei"
                        //                 , text                    : stakeNum.extend
                        //                 , fillColor               : ["#fff"]
                        //                 , verticalOrigin          : "BOTTOM"
                        //                 , pixelOffset             : [0, -7.5]
                        //                 , level                   : [0, 5e3]
                        //                 , disableDepthTestDistance: Number.POSITIVE_INFINITY
                        //             }
                        //         })
                        //     }
                        // });
                        //
                        // _this.items.push(_this.layer.dataSources.entities.add(HP.object));

                        _this.layer.pointPrimitives.add(
                            new uMap.PointOption(
                                $.extend({}, HPOption.point,
                                    {
                                        position: point.position
                                    })
                            )
                        );

                        _this.layer.labelPrimitives.add(
                            new uMap.LabelOption(
                                $.extend({}, HPOption.label,
                                    {
                                        position: point.position
                                        , text  : String(stakeNum.extend)
                                    })
                            )
                        );

                    }


                });

            }
        },
        "clear"     : {
            value: function () {
                var _this = this;

                $.each(_this.items, function (i, item) {
                    item.close();
                    item.listItem.remove();
                });

                _this._data = undefined;
                _this.items = [];
            }
        },
        "open"      : {
            value: function (forceReload) {
                var _this = this;

                _this.loadInit(function () {
                    _this.isOpened = true;
                    _this.layer.open();
                    _this.trigger("open");
                    _this.trigger("toggle");
                }, forceReload);


            }
        },
        "loadInit"  : {
            value: function (callback, forceReload) {

                var _this = this;

                if (forceReload || !_this.isLoaded) {


                    var queryNode = _this.app.queryManager.add(new QueryNode({
                        "title"   : "[模块] : " + _this.title,
                        "modality": true
                    }));

                    queryNode.trigger("send");

                    if (_this.request) {
                        _this.request.send({}, function (json) {
                            if (json.data.list && json.data.list.length > 0) {

                                _this.renderList(json.data.list);
                                _this.isLoaded = true;
                                _this.trigger("load");
                                queryNode.trigger("loaded");
                                callback && callback();
                            }
                        });
                    }


                } else {
                    callback && callback();
                }


            }
        },
        "close"     : {
            value: function () {
                var _this = this;
                _this.closePanel(false);
                _this.layer.close();
                _this.isOpened = false;
                _this.trigger("close");
                _this.trigger("toggle");
            }
        },
        "openPanel" : {
            value: function () {
                var _this = this;
                if (!_this.isOpened) {
                    _this.open();
                }

                _this.isPanelOpened = true;
                _this.trigger("openPanel");

            }
        }
    });

    return _class;

});